﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using HZ.Supervise.Model.Query;
namespace HZ.Supervise.Web.Common
{
    public partial class WebUserArea : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetDefaultAreaString();
            }
        }


        /// <summary>
        /// 获取默认选中的地区编号串
        /// </summary>
        /// <returns></returns>
        protected string GetDefaultAreaString()
        {
           
            //
            string strArea = "";
            HZ.Supervise.Model.User user = CurrentAccount.GetUser();

            //获取当前用户所在区域
            IBLL_Area ia = new HZ.Supervise.BLL.BLL_Area();
            IList<Area> lstArea = new List<Area>();
            string AreaID = user.Org.Area.AreaID;
            int outcount;
            lstArea = ia.GetSonAreas(AreaID,1,0,out outcount);
            //如果是市级中心机构，则默认选中具体城市
            if (AreaID.Equals(Constants.CURRENT_DEPLOY_AREAID)) //是否是省级单位；
            {
                foreach (Area area in lstArea)
                {
                    ListItem ddlitem = new ListItem();
                    ddlitem.Text = area.AreaName;
                    ddlitem.Value = area.AreaID;
                    ddlCity.Items.Add(ddlitem);
                }
                ListItem b = new ListItem();
                b.Text = "全部";
                b.Value = "";
                ddlCity.Items.Insert(0, b);
                ListItem c = new ListItem();
                c.Text = "全部";
                c.Value = "";
                ddlCountry.Items.Insert(0, c);
           
            }
            else if (AreaID.Equals("539900")) // 省直属
            {
                ListItem a = new ListItem();
                a.Text = "省直属";
                a.Value = "539900";
                ddlCity.Items.Insert(0, a);
              
                ListItem b = new ListItem();
                b.Text = "全部";
                b.Value = "";
                ddlCountry.Items.Insert(0, b);
              
            }
            else if (lstArea.Count > 0)//市级 
            {
                ListItem ddlitem = new ListItem();
                ddlitem.Text = HZ.Supervise.BLL.BLL_Cache.DicArea[user.Org.Area.AreaID].AreaName;
                ddlitem.Value = user.Org.Area.AreaID;
                ddlCity.Items.Add(ddlitem);
                ddlCountrydanding(lstArea);

            }
            else  //地区
            {
                ListItem b = new ListItem();
                b.Text = "全部";
                b.Value = "";
                ddlCity.Items.Insert(0, b);
               
                ListItem ddlitem = new ListItem();
                //ddlitem.Text = user.Org.Area.AreaName;
                ddlitem.Text = HZ.Supervise.BLL.BLL_Cache.DicArea[user.Org.Area.AreaID].AreaName;
                ddlitem.Value = user.Org.Area.AreaID;
                ddlCountry.Items.Add(ddlitem);
               
            }

            return strArea;
        }

        /// <summary>
        /// 绑定区域
        /// </summary>
        private void ddlCountrydanding(IList<Area> lstArea)
        {
            ddlCountry.Items.Clear();
            foreach (Area area in lstArea)
            {
                ListItem ddlitem = new ListItem();
                ddlitem.Text = area.AreaName;
                ddlitem.Value = area.AreaID;
                ddlCountry.Items.Add(ddlitem);
            }
            ListItem c = new ListItem();
            c.Text = "全部";
            c.Value = "";
            ddlCountry.Items.Insert(0, c); 
        }
       
    }
}
